<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="decorator" content="default" />
<title>主页报告</title>
<script type="text/javascript">
	$(document).ready(
		function() {
			$("#value").focus();
			$("#inputForm")
					.validate(
							{
								submitHandler : function(form) {
									form.submit();
								},
								errorContainer : "#messageBox",
								errorPlacement : function(error, element) {
									$("#messageBox").text("输入有误，请先更正。");
									if (element.is(":checkbox")
											|| element.is(":radio")
											|| element.parent().is(
													".input-append")) {
										error.appendTo(element.parent()
												.parent());
									} else {
										error.insertAfter(element);
									}
								}
							});
	});
	
	function updateAction(type) {
		if(type=='main') {
			$("#inputForm").attr('action','${ctx}/project/report/exportMainReport');
		}else {
			$("#inputForm").attr('action','${ctx}/project/report/exportViceReport');
		}
	}


	var initFunc = {
		subPro: function() {
			if(!$('#subPro').val() && $('#subPro').find('option').length==1)return;
			$('#subPro').html('<option value="">请选择单位工程</option>').val('').trigger('change');
		},
		gxh: function() {
			if(!$('#gxh').val() && $('#gxh').find('option').length==1)return;
			$('#gxh').html('<option value="">请选择管线号</option>').val('').trigger('change');
		},
		gg: function() {
			if(!$('#gg').val() && $('#gg').find('option').length==1)return;
			$('#gg').html('<option value="">请选择规格</option>').val('').trigger('change');
		},
		tzfs: function() {
			if(!$('#tzfs').val())return;
			$('#tzfs').val('').trigger('change');
		},
		yzl: function() {
			if(!$('#sxy').val())return;
			$('#sxy').val('').trigger('change');
		},
		og: function() {
			if(!$('#OG').val() && $('#OG').find('option').length==1)return;
			$('#OG').html('<option value="">请选择操作指导书编号</option>').val('').trigger('change');
		},
		cz: function() {
			if(!$('#CZ').val() && $('#CZ').find('option').length==1)return;
			$('#CZ').html('<option value="">请选择材质</option>').val('').trigger('change');
		}
	}
	function execInitFunc(funcArr) {
		for(var i=0;i<funcArr.length;i++) {
			initFunc[funcArr[i]]();
		}
	}

	function loadSubProject(projectId) {
		execInitFunc(['subPro','gxh','gg','tzfs','yzl','og']);
		if(!projectId) {
			return;
		}
		$.post(
			'${ctx}/project/subProject/listSubByPro',	
			{projectId: projectId},
			function(data, textStatus, jqXHR) {
				var html = '<option value="">请选择单位工程</option>';
				for(var i=0;i<data.length;i++) {
					html+= '<option value="'+data[i].id+'">'+data[i].name+'</option>';
				}
				$('#subPro').html(html);
			},'json');
	}
	
	function loadOGByGGAndTZFS() {
		var projectId = $('#projectId').val();
		if(!projectId) {
			showTip('请选择工程');
			execInitFunc(['subPro','gxh','gg','tzfs','yzl','og']);
			$('#projectId').focus();return;
		}
		var subProject = $('#subPro').val();
		if(!subPro) {
			execInitFunc(['gxh','gg','tzfs','yzl','og']);
			showTip('请选择单位工程');
			return;
		}
		var gg = $('#gg').val();
		if(!gg) {
			execInitFunc(['tzfs','yzl','og']);
			showTip('请选择规格');
			$('#gg').focus();return;
		}
		var tzfs = $('#tzfs').val();
		if(!tzfs) {
			execInitFunc(['yzl','og']);
			showTip('请选择透照方式');
			$('#tzfs').focus();return;
		}
		var sxy = $('#sxy').val();
		if(!sxy) {
			execInitFunc(['og']);
			showTip('请选择源种类');
			$('#sxy').focus();return;
		}

		$.post(
			'${ctx}/project/opGuide/listOGByGgAndTzfs',	
			{'project.id': projectId, 'gg': gg, 'tzfs': tzfs, 'yzl': sxy},
			function(data, textStatus, jqXHR) {
				var html = '<option value="">请选择操作指导书</option>';
				for(var i=0;i<data.length;i++) {
					html+= '<option value="'+data[i].id+'">'+data[i].czzdsbh+'</option>';
				}
				$('#OG').html(html);
			},'json');
		
	}
	
	function loadGXHBySub(subProjectId) {
		execInitFunc(['gxh','gg','tzfs','yzl','og']);
		if(!subProjectId) {
			return;
		}
		$.post(
			'${ctx}/project/tz/listGXHBySub',	
			{subProjectId: subProjectId},
			function(data, textStatus, jqXHR) {
				var html = '<option value="">请选择管线号</option>';
				for(var i=0;i<data.length;i++) {
					html+= '<option value="'+data[i].gxh+'">'+data[i].gxh+'</option>';
				}
				$('#gxh').html(html);
			},'json');
	}
	
	function loadGGlistBySubGXH(gxh) {
		execInitFunc(['gg','tzfs','yzl','og']);
		if(!gxh) {
			return;
		}
		var sub = $('#subPro').val();
		if(!sub) {
			showTip("请先选择单位工程",'error');
		}
		$.post(
				'${ctx}/project/tz/listGGBySub',	
				{subProjectId: sub, gxh: gxh},
				function(data, textStatus, jqXHR) {
					var html = '<option value="">请选择规格</option>';
					for(var i=0;i<data.length;i++) {
						html+= '<option value="'+data[i].id+'">'+data[i].id+'</option>';
					}
					$('#gg').html(html);
				},'json');
		
	}

	function loadCzByProjectOrOpGuide(opGuideId) {
		if(!opGuideId)return;
		$.post(
				'${ctx}/project/report/loadCzByProject',
				{opGuideId: opGuideId},
				function(data, textStatus, jqXHR) {
					var html = '<option value="">请选择材质</option>';
					if(data && data.status && data.status=='success') {
						for(var i=0;i<data.data.length;i++) {
							html+= '<option value="'+data.data[i]+'">'+data.data[i]+'</option>';
						}
					}
					$('#CZ').html(html);
				},'json');
	}
</script>
</head>
<body>
<br>
	<form:form id="inputForm"
		action="${ctx}/project/report/exportMainReport" method="post" class="form-horizontal" target="_blank">
		<common:message content="${message}" />
		<div class="control-group">
			<label class="control-label">工程:</label>
			<div class="controls">
				<select id="projectId" name="projectId" class="input-large required" onchange="loadSubProject(this.value)">
					<option value="">请选择工程</option>
					<c:forEach items="${projectList}" var="p">
						<option value="${p.id}">${p.name}</option>
					</c:forEach>
				</select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">单位工程:</label>
			<div class="controls">
			<select id="subPro" name="subProjectId" class="input-large required" onchange="loadGXHBySub(this.value)">
				<option value="">请选择单位工程</option>
			</select>
			<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">管线编号:</label>
			<div class="controls">
			<select id="gxh" name="gxh" class="input-large required" onchange="loadGGlistBySubGXH(this.value)">
				<option value="">请选择管线号</option>
			</select>
			<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">规格:</label>
			<div class="controls">
			<select id="gg" name="gg" class="input-large required" onchange="loadOGByGGAndTZFS()">
				<option value="">请选择规格</option>
			</select>
			<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">透照方式:</label>
			<div class="controls">
			<select id="tzfs" name="tzfs" class="input-large required" onchange="loadOGByGGAndTZFS()">
				<option value="">请选择透照方式</option>
				<c:forEach items="${fns:getDictList('dict_tzfs')}" var="t">
					<option value="${t.value}">${t.label}</option>
				</c:forEach>
			</select>
			<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">源种类:</label>
			<div class="controls">
				<select id="sxy" name="sxy" class="input-large required" onchange="loadOGByGGAndTZFS()">>
					<option value="">请选择源种类</option>
					<c:forEach items="${fns:getDictList('dict_yzl')}" var="dict">
						<option value="${dict.value}">${dict.label}</option>
					</c:forEach>
				</select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">操作指导书:</label>
			<div class="controls">
				<select id="OG" name="ogId" class="input-large  required" onchange="loadCzByProjectOrOpGuide(this.value)">
				<option value="">请选择操作指导书编号</option>
			</select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">材质:</label>--%>
			<%--<div class="controls">--%>
				<%--<select id="CZ" name="cz" class="input-large  required">--%>
					<%--<option value="">请选择材质</option>--%>
				<%--</select>--%>
				<%--<span class="help-inline"><font color="red">*</font> </span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">检测比例:</label>--%>
			<%--<div class="controls">--%>
				<%--<select id="JCBL" name="jcbl" class="input-large  required">--%>
					<%--<option value="">请选择检测比例</option>--%>
					<%--<c:forEach items="${fns:getDictList('dict_jcbl')}" var="dict">--%>
						<%--<option value="${dict.value}">${dict.label}</option>--%>
					<%--</c:forEach>--%>
				<%--</select>--%>
				<%--<span class="help-inline"><font color="red">*</font> </span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<%--<div class="control-group">--%>
			<%--<label class="control-label">合格级别:</label>--%>
			<%--<div class="controls">--%>
				<%--<select id="HGJB" name="hgjb" class="input-large  required">--%>
					<%--<option value="">请选择合格级别</option>--%>
					<%--<c:forEach items="${fns:getDictList('dict_hgjb')}" var="dict">--%>
						<%--<option value="${dict.value}">${dict.label}</option>--%>
					<%--</c:forEach>--%>
				<%--</select>--%>
				<%--<span class="help-inline"><font color="red">*</font> </span>--%>
			<%--</div>--%>
		<%--</div>--%>
		<div class="control-group">
			<label class="control-label">报告编号:</label>
			<div class="controls">
			<input name="num"  maxlength="50" class="required input-large" >
			<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">日期:</label>
			<div class="controls">
			<input name="dates"  maxlength="50" class="input-medium Wdate required" value="${dates}" onclick="WdatePicker({dateFmt:'yyyy年MM月dd日',isShowClear:false});">
			<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="form-actions">
			<input class="btn btn-primary" type="submit"
				value="导出主页" onmouseover="updateAction('main')"/>&nbsp; 
			<input class="btn btn-primary" type="submit"
				value="导出附页" onmouseover="updateAction('vice')"/>&nbsp; 
		</div>
	</form:form>
</body>
</html>